{{define "org/edit.html"}}
<!DOCTYPE html>
<html>
	<head>
        {{template "header"}}
	</head>

	<body>
		<div class="weadmin-nav">
            <span class="layui-breadcrumb">
                <a href="/welcome">首页</a>
                <a href="/admin/org/list">机构管理</a>
                <a><cite>修改机构</cite></a>
            </span>
		</div>
		<div class="weadmin-body">
			<form class="layui-form" lay-filter="org_edit">
				<div class="layui-form-item">
					<div class="layui-inline">
						<label for="L_orgname" class="layui-form-label">
							<span class="we-red">*</span>机构名称
						</label>
						<div class="layui-input-inline">
							<input type="text" id="L_orgname" name="orgname" lay-verify="orgname" autocomplete="off" class="layui-input" placeholder="机构名称" value="">
						</div>
					</div>

					<div class="layui-inline">
						<label for="L_sortnum" class="layui-form-label">
							<span class="we-red">*</span>排序号
						</label>
						<div class="layui-input-inline">
							<input type="text" id="L_sortnum" name="sortnum" lay-verify="required|number|sortnum" autocomplete="off" class="layui-input" placeholder="排序号" value="">
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<label for="L_parentid" class="layui-form-label">
						<span class="we-red">*</span>父级机构
					</label>
					<div class="layui-input-inline">
						<select name="parentid" lay-filter="parentid" id="L_parentid">
							<option value="0">顶级机构</option>
							{{ range .parentOrgList }}
							<option value="{{.Value}}" >{{.Text}}</option>
							{{ end }}
						</select>
					</div>
				</div>

				<div class="layui-form-item">
					<label for="L_state" class="layui-form-label">机构状态
					</label>
					<div class="layui-input-block">
						<input type="checkbox" name="state" id="L_state" lay-skin="switch"
								lay-text="启用|禁用" value="1">
					</div>
				</div>

				<div class="layui-form-item">
					<label for="L_remark" class="layui-form-label">备注
					</label>
					<div class="layui-input-block">
						<input type="text" id="L_remark" name="remark" lay-verify="remark" autocomplete="off" class="layui-input" placeholder="备注描述" value="">
					</div>
				</div>

				<div class="layui-form-item">
					<button class="layui-btn fr" lay-filter="edit" lay-submit="">确定</button>
				</div>
			</form>
		</div>
    </body>

    {{template "jsfile"}}
	<script type="text/javascript">
		layui.config({
		  base: '/static/js/',
		  admin: '/static/js/admin',
		}).use('iconPicker');
		layui.use(['jquery', 'form','element', 'admin', 'carousel','iconPicker'], function() {
			var element = layui.element,
				$ = layui.jquery,
				carousel = layui.carousel,
				form = layui.form,
				iconPicker = layui.iconPicker,
				admin = layui.admin;
			//建造实例
			carousel.render({
				elem: '.weadmin-shortcut'
				,width: '100%' //设置容器宽度
				,arrow: 'none' //始终显示箭头
				,trigger: 'hover'
				,autoplay:false
			});

			form.verify({
				orgname: function(value){
					if(value.length <= 0){
						return '机构名称不允许为空!';
					}
					if(value.length > 200){
						return '机构名称允许最大200字符!';
					}
				},
				sortnum: function(value){
					if(value.length <= 0){
						return '排序号不允许为空!';
					}
					if(value <= 0){
						return '排序号须为正整数!';
					}
				},
				remark: function(value){
					if(value.length > 500){
						return '备注允许最大500字符!';
					}
				},
			})

			//监听提交
			form.on('submit(edit)', function(data){
				$.ajax({
					url:'/admin/org/edit/'+'{{.org.Id}}',
					type:'PUT',
					data:data.field,
					dataType:'json',
					success: function(result){
						if(result.status){
							layer.msg("更新机构信息成功!",{time:3*1000,icon:1},function(){
								//自动关闭layer
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
								//刷新list
								parent.orgRefreshForm();
							})
						}else{
							layer.msg(result.message,{time:6*1000,icon:2})
						}
					}
				})
				return false;
			});

			//表单初始赋值
			form.val('org_edit', {
				"orgname": '{{.org.Name}}',
				"parentid": '{{.org.ParentId}}',
				"sortnum": '{{.org.Sortnum}}',
				"state": {{.org.State}},
				"remark": '{{.org.Remark}}'
			});
		});
	</script>

</html>
{{end}}